<template>
  <div :class="{ hidden: hidden }" class="pagination-container">
    <el-pagination
      :background="background"
      :current-page="page"
      :page-size="limit"
      :layout="layout"
      :page-sizes="pageSizes"
      :total="total"
      v-bind="$attrs"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script setup lang="ts">
interface Props {
  total: number
  page?: number
  limit?: number
  pageSizes?: number[]
  layout?: string
  background?: boolean
  hidden?: boolean
}

const props = withDefaults(defineProps<Props>(), {
  total: 0,
  page: 1,
  limit: 20,
  pageSizes: () => [10, 20, 30, 50, 100],
  layout: 'total, sizes, prev, pager, next, jumper',
  background: true,
  hidden: false
})

const emit = defineEmits<{
  (e: 'pagination', data: { page: number; limit: number }): void
}>()

function handleSizeChange(val: number) {
  emit('pagination', { page: props.page, limit: val })
}

function handleCurrentChange(val: number) {
  emit('pagination', { page: val, limit: props.limit })
}
</script>

<style scoped>
.pagination-container {
  background: #fff;
  padding: 32px 16px;
}

.pagination-container.hidden {
  display: none;
}
</style>